<template>
    <div class="dateChangeContainer">
        <el-dialog
                title="切换日期"
                ref="date"
                :visible.sync="dateChangeVisible"
                width="30%"
                :before-close="closedateChange"
        >
            <el-date-picker
                v-model="value1"
                type="date"
                placeholder="选择日期"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                >
            </el-date-picker>
            <span slot="footer" class="dialog-footer">
                <el-button @click="closedateChange">取 消</el-button>
                <el-button type="primary" @click="changedate">确 定</el-button>
            </span>
        </el-dialog>
        
    </div>
</template>

<script>
let Base64 = require('js-base64').Base64;
import appUtil from '~/assets/utils/appUtil.js';
export default {
    name: 'dateChange',
    props: ['dateChangeVisible'],
    data () {
        return {
            value1: '',
        };
    },
    created(){
        let dateV = Base64.decode(JSON.parse(localStorage.getItem('commonData')).svTransDate);
        // console.log(dateV);
        this.value1 = dateV;
    },
    methods: {
        // 确定修改日期
        changedate(){
            let param = {
                userId:appUtil.getSes('userId'),
                svAgencyCode:Base64.decode(JSON.parse(localStorage.getItem('commonData')).svAgencyCode),
                svAgencyName:Base64.decode(JSON.parse(localStorage.getItem('commonData')).svAgencyName),
                svAccountCode:Base64.decode(JSON.parse(localStorage.getItem('commonData')).svAcctCode),
                svAccountName:Base64.decode(JSON.parse(localStorage.getItem('commonData')).svAcctName),
                svRoleId:Base64.decode(JSON.parse(localStorage.getItem('commonData')).svRoleId),
                svRoleCode:Base64.decode(JSON.parse(localStorage.getItem('commonData')).svRoleCode),
                svRoleName:Base64.decode(JSON.parse(localStorage.getItem('commonData')).svRoleName),
                setYear:this.value1.slice(0,4),
                svTransDate:this.value1
            };
            this.$axios.get('/pf/portal/saveBaseDataToSession.do',{params:param}).then((res) => {
                console.log(res);
                // 子组件调用父组件的方法
                this.$parent.closeDate();
                window.location.reload();
            });
        },
        // 关闭弹框
        closedateChange () {
            this.$parent.closeDate();
        },
    },
};
</script>

<style lang="scss" scoped>

</style>
